package com.tarena.spring.boot.starter.config;

import com.tarena.spring.boot.starter.po.User;
import com.tarena.spring.boot.starter.properties.UserProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(UserProperties.class)//EnableConfigurationProperties注解类中采用了@Import引入了其他配置类，相当于：
//在一个spring的xml中引入另一个spring的xml：   在demo01.xml导入demo02.xml  <import resource="demo02.xml"/>
@Slf4j
//@ComponentScan(basePackages = {"com.tarena.spring.boot.starter.po"})//如果不加basePackages属性,会默认扫描当前配置类所在的包
public class UserAutoConfiguration {

    @Autowired
    private  UserProperties userProperties;

    @Bean
    @ConditionalOnProperty(prefix = "csmall", value = "enable",havingValue = "true")
    public User initUser(){
        log.debug("条件满足,user创建容器bean对象");
        User user=new User();
        return  user;
    }

}
